// Basic javascript function

// Function Name: addEvent
// Usage: e.g addEvent(window, 'load', function, false)
// http://www.wait-till-i.com/

function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

// Function Name: getElementsByClass
// Usage: e.g getElementsByClass('classname', document, 'div')
// http://www.dustindiaz.com/getelementsbyclass/

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
